#include <bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
int n,ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		int x;cin>>x;
		q.push(x);
	}
	for(int i=1;i<n;++i){
		int y=0;
		y+=q.top();
		q.pop();
		y+=q.top();
		q.pop();
		ans+=y;
		q.push(y);
	}
	cout<<ans<<endl;
	return 0;
}
